package com.tang;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

/**
 * 全局主题生产者
 */
public class GlobalProducer {
    public static void main(String[] args) throws Exception {
        //第二个参数开启消息追踪
        DefaultMQProducer producer = new DefaultMQProducer("producer_group",true);
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();
        for (int i = 0; i < 12; i++) {
            String info="message from Global_Producer :"+i;
            Message msg = new Message("Global_Orderly-Topic", "globalTag", info.getBytes());
            //setKeys这个方法就是设置每个消息的MessageKey
            msg.setKeys("Global_Orderly-Tag");
            producer.send(msg);
        }
        System.out.println("发送成功");
    }
}